package edu.xlh.travel.dao;

import edu.xlh.travel.pojo.SysLog;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

public interface SysLogDao extends JpaRepository<SysLog,String>, JpaSpecificationExecutor<SysLog> {

    @Query(value = "select * from t_sys_log " +
            "WHERE if(IFNULL(?1,'') !='',user_name like concat('%',?1,'%'),1=1) and " +
            "if(IFNULL(?2,'') !='',create_time like concat('%',?2,'%'),1=1) and " +
            "if(IFNULL(?3,'') !='',operation like concat('%',?3,'%'),1=1) and " +
            "if(IFNULL(?4,'') !='',method like concat('%',?4,'%'),1=1) and " +
            "if(IFNULL(?5,'') !='',time like concat('%',?5,'%'),1=1) order By create_time desc"
            ,nativeQuery = true )
    List<SysLog> QueryOnlineUserByCondition(String userName, Date createTime,
                                            String operation, String method, String time);

    @Transactional
    @Modifying
    @Query(value = "update SysLog set delFlag =?2 where id =?1")
    void updateSysLogDelFlagBySysLogId(String id, String s);
}
